package com.nuanshui.heatedloan.msgcenter.service;

import com.nuanshui.framework.lang.SysStringUtils;
import com.nuanshui.framework.utils.redis.JedisUtil;
import com.nuanshui.heatedloan.baseservice.service.CommonServiceImpl;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.msgcenter.constant.MsgCenterGlobalParams;
import com.nuanshui.heatedloan.msgcenter.facade.MsgReadStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(ServiceConstant.MSGREADSTATUSSERVICE)
public class MsgReadStatusServiceImpl extends CommonServiceImpl implements MsgReadStatusService {

    @Autowired
    private JedisUtil jedisUtil;

    public String getReadNum(String userId)
    {
        String key =  jedisUtil.get(MsgCenterGlobalParams.NOT_READ_NUM_PREFIX+userId);
        if(SysStringUtils.isEmpty(key))
            key="0";
        return key;
    }

    public String incrementAndGetReadNum(String userId)
    {
        jedisUtil.incr(MsgCenterGlobalParams.NOT_READ_NUM_PREFIX+userId);
        return getReadNum(userId);
    }

    public void resetReadNum(String userId)
    {
        jedisUtil.set(MsgCenterGlobalParams.NOT_READ_NUM_PREFIX+userId, "0");
    }
}
